package com.wwy.consumer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DeliverCallback;
import com.wwy.config.RabbitMqUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Objects;

/**
 * @author 王伟羽
 * @date 2024/3/13 13:47
 */
@Component
public class ConsumerFefualt {

    private final static String QUERE_NAME = "quere_name";

//    @Bean
//    public void consumeMessage() {
//        Connection connection = RabbitMqUtils.getConnection();
//        if (Objects.nonNull(connection)) {
//            try {
//                Channel channel = connection.createChannel();
//                channel.queueDeclare(QUERE_NAME, true, false, false, null);
////                // 第二步创建消费者
////                Consumer consumer  = new DefaultConsumer(channel){
////                    @Override
////                    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
////
////                        // byte[] body 就是消费者得到的数据
////
////                        System.out.println("消费者 得到消息body = " + new String(body,"utf-8"));
////
////                    }
////                };
////                channel.basicConsume(QUERE_NAME,true,consumer);
//                DeliverCallback deliverCallback = (consumerTag, delivery) -> {
//                    String message = new String(delivery.getBody(), "UTF-8");
//                    System.out.println(" [x] Received '" + message + "'");
//                };
//                channel.basicConsume(QUERE_NAME, true, deliverCallback, consumerTag -> {
//                });
//                // 让当前程序卡在 这里
//                System.in.read();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//    }
}
